package com.demo.exception;

import com.demo.config.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author： yu.Tan
 * @Date: 2020/8/27 14:11
 * @Description:
 */
@RestControllerAdvice(value = "com.demo")
public class RRExceptionHandler {

    private Logger logger = LoggerFactory.getLogger(getClass());


    /**
     * 自定义异常
     *
     * @param e
     * @return
     */
    @ExceptionHandler(RRException.class)
    public Response handleRRException(RRException e) {
        Response r = new Response();
        r.setCode(e.getCode());
        r.setMsg(e.getMsg());
        return r;
    }

    @ExceptionHandler(Exception.class)
    public Response handleException(Exception e) {
        logger.error(e.getMessage(), e);
        return Response.error(e.getMessage());
    }

}
